#include "cim_tools.h"
#include "ai_common.h"
#include <iostream>
#include <fstream>
using namespace  cim_tools;
size_t inW = 4;
int main(int argc, char** argv) {
    Timer timer;
    timer.reset();

    CIM_offline_utils ctu_offline;  
    CIM_online_utils ctu_online;
    LayerConfig layer_cfg;
    layer_cfg.shift_num = 15;
  
    layer_cfg.BASE_WT_ADDR = 0x96000000;
    layer_cfg.BASE_IN_ADDR = 0x95000000;  
    layer_cfg.BASE_RS_ADDR = 0x97000000;


    
    layer_cfg.input.alloc(128*4, inW);
    layer_cfg.weight.alloc(16*14, 128*4);
    layer_cfg.output.alloc(16*14, inW);
    layer_cfg.wt_inst_gen();
    layer_cfg.run_inst_gen();
    layer_cfg.single_run_inst_gen();
    layer_cfg.data_rand_generator();
    ctu_offline.layer_config = layer_cfg;
    ctu_offline.run("./offline_log");


    ctu_online.layer_config = layer_cfg;

    // ctu_online.layer_config._weight.alloc(16*14 * 128*4 / 4);
    // ctu_online.layer_config._input.alloc(128*4 * inW / 4);
    // size_t in_size = read_bin_file("./ddr128_act.bin", ctu_online.layer_config._input.data);
    // assert(in_size == ctu_online.layer_config._input.numel() && "Input size mismatch");
    // size_t wt_size = read_bin_file("./ddr128_wet.bin", ctu_online.layer_config._weight.data);
    // assert(wt_size == ctu_online.layer_config._weight.numel() && "Weight size mismatch");
    
    ctu_online.pmem_mmap_init();
    ctu_online.cfg_init();
    ctu_online.wt_init();
    timer.start();
    ctu_online.run("./online_log");
    ctu_online.step_run("./online_step_run_log");
    timer.stop();
    timer.print("CIM online run time");

    // for (int i = 0; i < layer_cfg.inst_run.size(); i++) {
    //     printf("inst_run[%d]: 0x%08x\n", i, ctu_online.layer_config.inst_run[i]);
    // }





}

  



